#include "ParticleProjectile.h"

#include "ParticleContext.h"
#include "DescriptorParticle.h"

#include "ParticleSimple.h"

using namespace ParticleEngine;

const DescriptorParticle ParticleProjectile::Descriptor
(
"Projectile",
[](ParticleContext& NewContext) { return new ParticleProjectile(NewContext); }
);

ParticleProjectile::ParticleProjectile(ParticleContext& NewContext) :
ParticleBase(NewContext, &ParticleProjectile::Descriptor)
{
}

ParticleProjectile::~ParticleProjectile(void)
{
}

void ParticleProjectile::Sole()
{
	if (Acceleration.LengthSquare() > 0.0005f)
	{
		ParticleBase* NewParticle;

		NewParticle = new ParticleSimple(this->Context);
		NewParticle->Pos = this->Pos + Context.GetRandomVector();
		NewParticle->Velocity = this->Velocity * 0.3333333f;
		this->Context.ToAddArray.Add(NewParticle);

		NewParticle = new ParticleSimple(this->Context);
		NewParticle->Pos = this->Pos + Context.GetRandomVector();
		NewParticle->Velocity = this->Velocity * 0.3333333f;
		this->Context.ToAddArray.Add(NewParticle);

		NewParticle = new ParticleSimple(this->Context);
		NewParticle->Pos = this->Pos + Context.GetRandomVector();
		NewParticle->Velocity = this->Velocity * 0.3333333f;
		this->Context.ToAddArray.Add(NewParticle);

		this->Context.ToRemoveArray.Add(this);
	}

	this->SoleStandard();
}
